#pragma once
#include<memory>
#include<iostream>
#include<cstdint>
#include<iomanip>
#include"Singleton.h"
#include<functional>
#include<map>
#include<unordered_map>
#include<atomic>
#include<queue>
#include<mutex>
#include<condition_variable>

class Defer {
	public:
	Defer(std::function<void()> func) : func_(std::move(func)), active_(true) {}
	~Defer() {
		if (active_) {
			func_();
		}
	}
	void cancel() {
		active_ = false;
	}
private:
	std::function<void()> func_;
	bool active_;
};